//package com.maikang.exammall.util;
//
//import ch.qos.logback.classic.spi.LoggingEvent;
//import ch.qos.logback.core.UnsynchronizedAppenderBase;
//import com.maikang.exammall.entity.MallLog;
//import com.maikang.exammall.repository.LogRepository;
//import org.springframework.beans.BeansException;
//import org.springframework.context.ApplicationContext;
//import org.springframework.context.ApplicationContextAware;
//import org.springframework.stereotype.Component;
//
//import java.util.Date;
//
//@Component
//public class MongoDBAppender extends UnsynchronizedAppenderBase<LoggingEvent> implements ApplicationContextAware {
//    private static LogRepository logRepository;
//    @Override
//    protected void append(LoggingEvent loggingEvent) {
//        MallLog mallLog = new MallLog();
//        mallLog.setLevel(loggingEvent.getLevel().toString());
//        mallLog.setMessage(loggingEvent.getFormattedMessage());
//        mallLog.setThread(loggingEvent.getThreadName());
//        mallLog.setTs(new Date());
//        logRepository.save(mallLog);
//    }
//    @Override
//    public void start() {
//        super.start();
//    }
//    @Override
//    public void stop() {
//        super.stop();
//    }
//    @Override
//    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
//        if (applicationContext.getAutowireCapableBeanFactory()
//                .getBean(LogRepository.class)!=null){
//            logRepository = applicationContext
//                    .getAutowireCapableBeanFactory().getBean(LogRepository.class);
//        }
//    }
//}